﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufInfo.h"
#include "GnufListControl.h"

namespace gnuf {
    class NameValuePair;
    class QtList;
    class Toolbar;
    class Block;
    class GNUF_BASE_EXPORT List final
        : public ItemWith<QtList>
        , public ListControlAdpatation
    {
        GNUF_WATCHABLE_OBJECT(List);
        CANNOT_COPY_OR_ASSIGN(List);
    public:
        static const EItemType Type;
        explicit List(Item*);
        virtual ~List();
        void AddItem(gcmp::OwnerPtr<Info>& info);
        void InsertItemAt(int index, gcmp::OwnerPtr<Info>& info);
        void DeleteItemAt(int index);
        void ClearItem();

        int GetSelectedIndex() const { return m_currIndex; }
        void SetSelectedIndex(int index, bool outside = true);
        void SetText(const std::wstring& text);

        const std::vector<gcmp::OwnerPtr<Info>>& GetItemInfos() { return m_itemInfos; }
        std::wstring Text() const;

        void blockSignal(bool);
        bool signalBlocked() const { return m_blockSignal; }


        void setDisplayText(const std::wstring &);
        const std::wstring & displayText() const { return m_displayText; }
    protected:
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAbilityChanged() override;
        virtual void onPostAppearanceSettingChanged() override;
        virtual void onTableRowSelectionChanged(bool) override;
        // Inherits from ListControlAdpatation...
        virtual void onCurrentIndexChanged(int index) override;
        virtual void onAbilityChanged(bool) override;
        virtual void onCollectLocation(std::set<const gcmp::UniqueString *> &) const override;

    private:
        int GetDefaultSelectedIndex();
        std::vector<gcmp::OwnerPtr<Info>> m_itemInfos;
        int m_currIndex;
        bool m_blockSignal;
        std::wstring m_displayText;
    };
}
